package com.huige.wiki.controller;

import com.huige.wiki.req.EbookQueryReq;
import com.huige.wiki.req.EbookSaveReq;
import com.huige.wiki.resp.EbookQueryResp;
import com.huige.wiki.resp.PageResp;
import com.huige.wiki.service.EbookService;
import com.huige.wiki.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "电子书相关接口")
@RequestMapping("/ebook")
public class EbookController {

    @Autowired
    EbookService ebookService;

    @GetMapping("/list")
    @ApiOperation("查询电子书")
    public Result<PageResp<EbookQueryResp>> list(@Validated EbookQueryReq ebookQueryReq){
        log.info("查询电子书列表参数，{}",ebookQueryReq);
        PageResp<EbookQueryResp> pageResp = ebookService.list(ebookQueryReq);
        return Result.success(pageResp);
    }

    @PostMapping("/save")
    @ApiOperation("编辑电子书（新增或修改）")
    public Result save(@RequestBody @Validated EbookSaveReq ebookQueryReq){
        ebookService.save(ebookQueryReq);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除电子书")
    public Result delete(@PathVariable Long id){
        ebookService.delete(id);
        return Result.success();
    }


}
